package com.qire.manhua.controller;

import android.view.View;

import com.qire.antsrouter.AntsRouter;
import com.qire.antsrouter.card.FloorCard;
import com.qire.common.constant.Url;
import com.qire.common.support.base.EventController;
import com.qire.common.constant.Navigation;
import com.qire.manhua.BR;
import com.qire.manhua.activity.helper.LoginRouter;
import com.qire.manhua.fragment.UserCenterFragment;
import com.qire.manhua.model.enumeration.VipPrivilegeType;
import com.qire.manhua.model.viewModel.impl.UserCenterViewModel;
import com.qire.other.recorder.ComicActionRecorder;
import com.scwang.smart.refresh.layout.api.RefreshLayout;

import androidx.databinding.ViewDataBinding;

public class UserCenterController extends EventController<UserCenterFragment> {

    private UserCenterViewModel viewModel;

    public UserCenterController(UserCenterFragment fragment) {
        super(fragment);
    }

    @Override
    protected void bindView() {
        ViewDataBinding binder = owner.viewDataBinder();
        if(binder != null) {
            binder.setVariable(BR.userCenterController, this);
        }
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        this.viewModel = null;
    }

    public void onAddition(UserCenterViewModel viewModel) {
        this.viewModel = viewModel;
    }

    /*************************************************************************************************************************/

    public void refreshLayoutOnRefresh(RefreshLayout refreshLayout) {
        viewModel.refreshUserDetailData();
    }

    public void userPanelOnClick(View view) {
        AntsRouter.ROUTER.buildCard(Navigation.Page.UserProfileEditPage).navigation();
    }

    // 金币记录
    public void coinRecordsBtnOnClick(View view) {
        AntsRouter.ROUTER.buildCard(Navigation.Page.AccountDetailCoinPage).navigation();
    }

    // 金豆记录
    public void beanRecordsBtnOnClick(View view) {
        AntsRouter.ROUTER.buildCard(Navigation.Page.AccountDetailBeanPage).navigation();
    }


    public void goBuyMembershipBtnOnClick(View view) {
        AntsRouter.ROUTER.buildCard(Navigation.Page.BuyMembershipPage).navigation();
    }

    public void vipInstructionsBtnOnClick(View view) {
        VipPrivilegeType type = (VipPrivilegeType) view.getTag();
        AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.VipInstructionsPage)
                .withData("type", type)
                .navigation();
    }

    public void accountBalanceBtnOnClick(View view) {
        AntsRouter.ROUTER.buildCard(Navigation.Page.AccountPage).navigation();
    }

    public void rechargeBtnOnclick(View view) {
        AntsRouter.ROUTER.buildCard(Navigation.Page.BuyCoinsMarketPage).navigation();
        // 行为数据统计
        ComicActionRecorder.build(ComicActionRecorder.count_recharge_show)
                .setSource("用户中心充值按钮")
                .doRecorde(view.getContext());
    }

    public void taskBtnOnClick(View view) {
        AntsRouter.ROUTER.buildCard(Navigation.Page.TaskCenterPage).navigation();
    }

    public void messageBtnOnClick(View view) {
        AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.MessageCenterPage).navigation();
    }

    public void inviteFriendsBtnOnClick(View view) {
        AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.InviteFriendsPage).navigation();
    }

    public void systemSetupBtnOnClick(View view) {
        AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.SystemSetupPage).navigation();
    }

    public void helpAndFeedbackBtnOnClick(View view) {
        // 未登录先登录
        if(!LoginRouter.ROUTER.checkLoginRouteIfNeed()) {
            AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.WebPage)
                    .withData("title","帮助与反馈")
                    .withData("url", Url.helpAndFeedback_url)
                    .navigation();
        }
    }

}
